<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use DB;

/**
 * Class RunGameReward
 * @package App
 */
class RunGameReward extends Model
{
    public $timestamps = false;
    protected $table = "run_game_reward";

    const USE_NO = 0;
    const USE_YES = 1;

    static $UseDisplay = [
        self::USE_NO => '禁用',
        self::USE_YES => '使用',
    ];


    /**
     * 奖品列表
     * @param $user_id
     * @return array
     */
    static function Rewards($user_id)
    {
        $data = [];
        $rewards = RunGameReward::select('id', 'ranking', 'title', 'img', 'detail')->where('ranking', '>', 0)->where('is_use', self::USE_YES)->orderBy('ranking')->get();
        foreach ($rewards as $reward) {
            $data[] = [
                'id' => $reward->id,
                'ranking' => $reward->ranking,
                'title' => $reward->title,
                'img' => $reward->img,
                'detail' => $reward->detail,
                'price_id' => RunGamePrize::IsReceived($user_id, $reward->id),
            ];
        }
        //是否有未领取的奖励
        $price = RunGamePrize::HasPrice($user_id);
        return success(compact('data', 'price'));
    }

    /**
     * 奖品详情
     * @param $user_id
     * @return array
     */
    static function RewardInfo($user_id)
    {
        $reward = RunGameReward::select('id', 'ranking', 'title', 'img', 'detail')->find(request('reward_id'));
        $data = [
            'id' => $reward->id,
            'ranking' => $reward->ranking,
            'title' => $reward->title,
            'img' => $reward->img,
            'detail' => $reward->detail,
            'price_id' => RunGamePrize::IsReceived($user_id, $reward->id),
        ];
        return success(compact('data'));
    }
}
